<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 5.4.0">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon-next.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32-next.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16-next.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">

<link rel="stylesheet" href="/css/main.css">


<link rel="stylesheet" href="/lib/font-awesome/css/all.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"wan-lei8.gitee.io","root":"/","scheme":"Pisces","version":"7.8.0","exturl":false,"sidebar":{"position":"left","display":"post","padding":18,"offset":12,"onmobile":false},"copycode":{"enable":false,"show_result":false,"style":null},"back2top":{"enable":true,"sidebar":false,"scrollpercent":false},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":false,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":false,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}}};
  </script>

  <meta name="description" content="实现思路">
<meta property="og:type" content="article">
<meta property="og:title" content="异步导出">
<meta property="og:url" content="https://wan-lei8.gitee.io/2021/11/17/%E5%BC%82%E6%AD%A5%E5%AF%BC%E5%87%BA/index.html">
<meta property="og:site_name" content="程序员西桐">
<meta property="og:description" content="实现思路">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2021-11-17T07:16:50.000Z">
<meta property="article:modified_time" content="2021-11-17T07:41:11.972Z">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://wan-lei8.gitee.io/2021/11/17/%E5%BC%82%E6%AD%A5%E5%AF%BC%E5%87%BA/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome : false,
    isPost : true,
    lang   : 'zh-CN'
  };
</script>

  <title>异步导出 | 程序员西桐</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <a href="/" class="brand" rel="start">
      <span class="logo-line-before"><i></i></span>
      <h1 class="site-title">程序员西桐</h1>
      <span class="logo-line-after"><i></i></span>
    </a>
      <p class="site-subtitle" itemprop="description">但行好事，莫问前程</p>
  </div>

  <div class="site-nav-right">
    <div class="toggle popup-trigger">
    </div>
  </div>
</div>




<nav class="site-nav">
  <ul id="menu" class="main-menu menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-home fa-fw"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-tags fa-fw"></i>标签</a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-th fa-fw"></i>分类</a>

  </li>
  </ul>
</nav>




</div>
    </header>

    
  <div class="back-to-top">
    <i class="fa fa-arrow-up"></i>
    <span>0%</span>
  </div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content post posts-expand">
            

    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block" lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://wan-lei8.gitee.io/2021/11/17/%E5%BC%82%E6%AD%A5%E5%AF%BC%E5%87%BA/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.png">
      <meta itemprop="name" content="">
      <meta itemprop="description" content="">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="程序员西桐">
    </span>
      <header class="post-header">
        <h1 class="post-title" itemprop="name headline">
          异步导出
        </h1>

        <div class="post-meta">
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="far fa-calendar"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>
              

              <time title="创建时间：2021-11-17 15:16:50 / 修改时间：15:41:11" itemprop="dateCreated datePublished" datetime="2021-11-17T15:16:50+08:00">2021-11-17</time>
            </span>

          

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p><strong>实现思路</strong></p>
<span id="more"></span>

<ol>
<li><h5 id="封装查询导出数据的请求参数转成JSON字符串"><a href="#封装查询导出数据的请求参数转成JSON字符串" class="headerlink" title="封装查询导出数据的请求参数转成JSON字符串"></a>封装查询导出数据的请求参数转成JSON字符串</h5></li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@GetMapping(value = &quot;sellerAuthenticationExport&quot;, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)</span></span><br><span class="line"><span class="meta">@ApiOperation(&quot;区域客户认证信息导出&quot;)</span></span><br><span class="line"><span class="function"><span class="keyword">public</span> Boolean <span class="title">sellerAuthenticationExport</span><span class="params">(UserAuthenticationForQueryParam param)</span> </span>&#123;</span><br><span class="line">    log.info(<span class="string">&quot;seller.user.authentication.export, paramRequest = &#123;&#125;&quot;</span>, param);</span><br><span class="line">    param.setSellerId(RequestContext.getShopId().toString());</span><br><span class="line">    UserRegionRelationsPagingRequest userRegionRelationsPagingRequest = getUserRegionRelationsPagingRequest2(param);</span><br><span class="line">    String jsonString = JSON.toJSONString(userRegionRelationsPagingRequest);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ol start="2">
<li><h5 id="封装导出信息包括文件类型、文件名、报表类型、所属中台"><a href="#封装导出信息包括文件类型、文件名、报表类型、所属中台" class="headerlink" title="封装导出信息包括文件类型、文件名、报表类型、所属中台"></a>封装导出信息包括文件类型、文件名、报表类型、所属中台</h5></li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">UserExcelExportCreateRequest excelRequest = <span class="keyword">new</span> UserExcelExportCreateRequest();</span><br><span class="line">excelRequest.setOperatorId(RequestContext.getShopId());</span><br><span class="line">excelRequest.setUserId(RequestContext.getUserId());</span><br><span class="line">excelRequest.setFileType(<span class="string">&quot;区域客户认证信息&quot;</span>);</span><br><span class="line">excelRequest.setFileName(<span class="string">&quot;区域客户认证信息&quot;</span>+ TimeUtils.format(<span class="keyword">new</span> Date(),<span class="string">&quot;yyyyMMddHHmmss&quot;</span>));</span><br><span class="line">excelRequest.setReportType(<span class="string">&quot;seller_user_authentication_export&quot;</span>);</span><br><span class="line">excelRequest.setCenter(<span class="string">&quot;user&quot;</span>);</span><br><span class="line">excelRequest.setRequestJson(jsonString);</span><br></pre></td></tr></table></figure>

<ol start="3">
<li><h5 id="远程调用misc综合服务保存导出信息"><a href="#远程调用misc综合服务保存导出信息" class="headerlink" title="远程调用misc综合服务保存导出信息"></a>远程调用misc综合服务保存导出信息</h5></li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">ExcelReportCreateRequest excelRequest = <span class="keyword">new</span> ExcelReportCreateRequest();</span><br><span class="line">excelRequest.setParam(ExcelReportParam</span><br><span class="line">        .builder()</span><br><span class="line">        .operatorId(request.getOperatorId())</span><br><span class="line">        .userId(request.getUserId())</span><br><span class="line">        .fileType(request.getFileType())</span><br><span class="line">        .fileName(request.getFileName())</span><br><span class="line">        .center(request.getCenter())</span><br><span class="line">        .requestJson(request.getRequestJson())</span><br><span class="line">        .reportType(request.getReportType())</span><br><span class="line">        .createTime(<span class="keyword">new</span> Date())</span><br><span class="line">        .build());</span><br><span class="line">log.info(<span class="string">&quot;:::::::::::::::::::::::&quot;</span>+excelRequest.getParam().getFileName());</span><br><span class="line">excelReportWriteFacade.create(excelRequest);</span><br></pre></td></tr></table></figure>

<ol start="4">
<li><h5 id="使用定时任务每三分钟读取misc需要导出信息"><a href="#使用定时任务每三分钟读取misc需要导出信息" class="headerlink" title="使用定时任务每三分钟读取misc需要导出信息"></a>使用定时任务每三分钟读取misc需要导出信息</h5><ul>
<li>elastic-job定时任务配置</li>
</ul>
<p>​    （1）通过**@ConditionalOnProperty**注解控制定时任务开关</p>
<p>​    （ 2）声明Job配置类配置定时任务</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Configuration</span></span><br><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@RequiredArgsConstructor</span></span><br><span class="line"><span class="meta">@ConditionalOnProperty(name = &quot;userESign.task.enable&quot;, havingValue = &quot;true&quot;, matchIfMissing = true)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">CommonJobConfig</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> ZookeeperRegistryCenter regCenter;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> SyncESignAuthenticationInfoJob syncESignAuthenticationInfoJob;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> SyncESignContractJob syncESignContractJob;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> SyncESignFlowJob syncESignFlowJob;</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> ExcelExportJob excelExportJob;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">private</span> LiteJobConfiguration <span class="title">getLiteJobConfiguration</span><span class="params">(</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="keyword">final</span> Class&lt;? extends SimpleJob&gt; jobClass,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="keyword">final</span> String cron,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="keyword">final</span> <span class="keyword">int</span> shardingTotalCount,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="keyword">final</span> String shardingItemParameters)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> LiteJobConfiguration.newBuilder(</span><br><span class="line">                <span class="keyword">new</span> SimpleJobConfiguration(</span><br><span class="line">                        JobCoreConfiguration.newBuilder(</span><br><span class="line">                                jobClass.getName(),</span><br><span class="line">                                cron, shardingTotalCount</span><br><span class="line">                        ).shardingItemParameters(shardingItemParameters).build(),</span><br><span class="line">                        jobClass.getCanonicalName()</span><br><span class="line">                )</span><br><span class="line">        ).overwrite(<span class="keyword">true</span>).build();</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 通过流程flowId下沉认证数据</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> cron</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> shardingTotalCount</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> shardingItemParameters</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean(initMethod = &quot;init&quot;)</span></span><br><span class="line">    <span class="meta">@ConditionalOnProperty(name = &quot;userESign.task.SyncESignAuthenticationInfoJob.enable&quot;, havingValue = &quot;true&quot;, matchIfMissing = true)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> JobScheduler <span class="title">syncESignAuthenticationInfoJobScheduler</span><span class="params">(</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.SyncESignAuthenticationInfoJob.cron: 0/1 * * * * ?&#125;&quot;)</span> <span class="keyword">final</span> String cron,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.simpleJob.shardingTotalCount: 1&#125;&quot;)</span> <span class="keyword">final</span> <span class="keyword">int</span> shardingTotalCount,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.simpleJob.shardingItemParameters&#125;&quot;)</span> <span class="keyword">final</span> String shardingItemParameters)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> SpringJobScheduler(</span><br><span class="line">                syncESignAuthenticationInfoJob,</span><br><span class="line">                regCenter,</span><br><span class="line">                getLiteJobConfiguration(</span><br><span class="line">                        syncESignAuthenticationInfoJob.getClass(),</span><br><span class="line">                        cron,</span><br><span class="line">                        shardingTotalCount,</span><br><span class="line">                        shardingItemParameters)</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 合同信息</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> cron</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> shardingTotalCount</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> shardingItemParameters</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean(initMethod = &quot;init&quot;)</span></span><br><span class="line">    <span class="meta">@ConditionalOnProperty(name = &quot;userESign.task.SyncESignContractJob.enable&quot;, havingValue = &quot;true&quot;, matchIfMissing = true)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> JobScheduler <span class="title">syncESignContractJobScheduler</span><span class="params">(</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.SyncESignContractJob.cron: 1/2 * * * * ?&#125;&quot;)</span> <span class="keyword">final</span> String cron,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.simpleJob.shardingTotalCount: 1&#125;&quot;)</span> <span class="keyword">final</span> <span class="keyword">int</span> shardingTotalCount,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.simpleJob.shardingItemParameters&#125;&quot;)</span> <span class="keyword">final</span> String shardingItemParameters)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> SpringJobScheduler(</span><br><span class="line">                syncESignContractJob,</span><br><span class="line">                regCenter,</span><br><span class="line">                getLiteJobConfiguration(</span><br><span class="line">                        syncESignContractJob.getClass(),</span><br><span class="line">                        cron,</span><br><span class="line">                        shardingTotalCount,</span><br><span class="line">                        shardingItemParameters)</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 通过流程数据发起签署合同</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> cron</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> shardingTotalCount</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> shardingItemParameters</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean(initMethod = &quot;init&quot;)</span></span><br><span class="line">    <span class="meta">@ConditionalOnProperty(name = &quot;userESign.task.SyncESignFlowJob.enable&quot;, havingValue = &quot;true&quot;, matchIfMissing = true)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> JobScheduler <span class="title">syncESignFlowJobScheduler</span><span class="params">(</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.SyncESignFlowJob.cron: 0 */1 * * * ?&#125;&quot;)</span> <span class="keyword">final</span> String cron,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.simpleJob.shardingTotalCount: 1&#125;&quot;)</span> <span class="keyword">final</span> <span class="keyword">int</span> shardingTotalCount,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.simpleJob.shardingItemParameters&#125;&quot;)</span> <span class="keyword">final</span> String shardingItemParameters)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> SpringJobScheduler(</span><br><span class="line">                syncESignFlowJob,</span><br><span class="line">                regCenter,</span><br><span class="line">                getLiteJobConfiguration(</span><br><span class="line">                        syncESignFlowJob.getClass(),</span><br><span class="line">                        cron,</span><br><span class="line">                        shardingTotalCount,</span><br><span class="line">                        shardingItemParameters)</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 导出数据</span></span><br><span class="line"><span class="comment">     *</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> cron</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> shardingTotalCount</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> shardingItemParameters</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Bean(initMethod = &quot;init&quot;)</span></span><br><span class="line">    <span class="meta">@ConditionalOnProperty(name = &quot;userESign.task.SyncESignFlowJob.enable&quot;, havingValue = &quot;true&quot;, matchIfMissing = true)</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> JobScheduler <span class="title">syncExcelExportJob</span><span class="params">(</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.ExcelExportJob.cron: 0 */1 * * * ?&#125;&quot;)</span> <span class="keyword">final</span> String cron,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.simpleJob.shardingTotalCount: 1&#125;&quot;)</span> <span class="keyword">final</span> <span class="keyword">int</span> shardingTotalCount,</span></span></span><br><span class="line"><span class="params"><span class="function">            <span class="meta">@Value(&quot;$&#123;userESign.task.simpleJob.shardingItemParameters&#125;&quot;)</span> <span class="keyword">final</span> String shardingItemParameters)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">return</span> <span class="keyword">new</span> SpringJobScheduler(</span><br><span class="line">                excelExportJob,</span><br><span class="line">                regCenter,</span><br><span class="line">                getLiteJobConfiguration(</span><br><span class="line">                        excelExportJob.getClass(),</span><br><span class="line">                        cron,</span><br><span class="line">                        shardingTotalCount,</span><br><span class="line">                        shardingItemParameters)</span><br><span class="line">        );</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>​    （3）配置文件配置执行时间</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line">userESign:</span><br><span class="line">  task: #定时任务控制</span><br><span class="line">    enable: <span class="keyword">true</span> #定时任务总开关，<span class="keyword">false</span> 所有任务关闭</span><br><span class="line">    regCenter: #elastic-job配置</span><br><span class="line">      serverList: $&#123;ELASTICJOB_HOST:localhost:<span class="number">2181</span>&#125;</span><br><span class="line">      namespace: parana.wallet.task</span><br><span class="line">    simpleJob: #task-shardingTotalCount</span><br><span class="line">      shardingTotalCount: <span class="number">1</span></span><br><span class="line">      shardingItemParameters:</span><br><span class="line">    SyncESignAuthenticationInfoJob:</span><br><span class="line">      enable: <span class="keyword">true</span></span><br><span class="line">      cron: <span class="number">0</span>/<span class="number">3</span> * * * * ?</span><br><span class="line">    SyncESignContractJob:</span><br><span class="line">      enable: <span class="keyword">true</span></span><br><span class="line">      cron: <span class="number">0</span>/<span class="number">4</span> * * * * ?</span><br><span class="line">    SyncESignFlowJob:</span><br><span class="line">      enable: <span class="keyword">true</span></span><br><span class="line">      cron: <span class="number">0</span> <span class="number">0</span>/<span class="number">5</span> * * * ?</span><br><span class="line">    ExcelExportJob:</span><br><span class="line">      enable: <span class="keyword">true</span></span><br><span class="line">      cron: <span class="number">0</span> <span class="number">0</span>/<span class="number">3</span> * * * ?</span><br></pre></td></tr></table></figure>

<ul>
<li>执行具体定时任务</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@RequiredArgsConstructor</span></span><br><span class="line"><span class="meta">@ConditionalOnProperty(name = &quot;userESign.task.enable&quot;, havingValue = &quot;true&quot;, matchIfMissing = true)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">ExcelExportJob</span> <span class="keyword">implements</span> <span class="title">SimpleJob</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">static</span> <span class="keyword">final</span> DateTimeFormatter DFT = DateTimeFormat.forPattern(<span class="string">&quot;yyyy-MM-dd HH:mm:ss&quot;</span>);</span><br><span class="line">    <span class="keyword">private</span> <span class="keyword">final</span> UserExcelExportManager excelExportManager;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">execute</span><span class="params">(ShardingContext shardingContext)</span> </span>&#123;</span><br><span class="line">        runJob(shardingContext.getJobParameter());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">runJob</span><span class="params">(String shardingContext)</span> </span>&#123;</span><br><span class="line">        log.info(<span class="string">&quot;[USER-E-SIGN-JOB] ExcelExportJob begin &#123;&#125;&quot;</span>, DFT.print(DateTime.now()));</span><br><span class="line">        Stopwatch stopwatch = Stopwatch.createStarted();</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            <span class="comment">//具体要执行的任务</span></span><br><span class="line">            excelExportManager.execute();</span><br><span class="line">        &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">            log.error(<span class="string">&quot;ExcelExportJob fail, error:&#123;&#125;&quot;</span>, Throwables.getStackTraceAsString(e));</span><br><span class="line">        &#125;</span><br><span class="line">        stopwatch.stop();</span><br><span class="line">        log.info(<span class="string">&quot;[USER-E-SIGN-JOB] ExcelExportJob done at &#123;&#125; cost &#123;&#125; ms&quot;</span>, DFT.print(DateTime.now()),</span><br><span class="line">                stopwatch.elapsed(TimeUnit.MILLISECONDS));</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>任务中引入远程调用需要使用的Facade</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserExcelExportManager</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//misc 读服务</span></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> ExcelReportReadFacade excelReportReadFacade;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//misc 写服务</span></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> ExcelReportWriteFacade excelReportWriteFacade;</span><br><span class="line"></span><br><span class="line">    <span class="comment">//导出开始执行Service</span></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> UserExcelExportStrategyService excelExportStrategyService;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 查询导出数据接口</span></span><br><span class="line"><span class="comment">     * 每一个导出任务对应一个导出类型</span></span><br><span class="line"><span class="comment">     * 根据导出类型执行对应的数据查询</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> List&lt;ExcelExportStrategy&gt; excelExportStrategies;</span><br></pre></td></tr></table></figure></li>
<li><p>任务开始通过misc获取要导出的任务计划有就修改任务计划状态为生成中</p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="function"><span class="keyword">public</span> <span class="keyword">void</span> <span class="title">execute</span><span class="params">()</span> </span>&#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="comment">//删除超过一星期数据</span></span><br><span class="line">    excelReportWriteFacade.deleteWeekAgo(<span class="string">&quot;user&quot;</span>);</span><br><span class="line"></span><br><span class="line">    <span class="comment">//根据所属中台获取导出任务</span></span><br><span class="line">    Response&lt;List&lt;ExcelReportInfo&gt;&gt; newExcelResponse = excelReportReadFacade.getNewExcel(<span class="string">&quot;user&quot;</span>);</span><br><span class="line">    <span class="keyword">if</span> (!newExcelResponse.isSuccess()) &#123;</span><br><span class="line">        <span class="keyword">throw</span> <span class="keyword">new</span> ServiceException(newExcelResponse.getError());</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    Long time = System.currentTimeMillis();</span><br><span class="line">    log.info(time + <span class="string">&quot;===========&quot;</span>);</span><br><span class="line">    <span class="comment">//遍历所有具体导出任务</span></span><br><span class="line">    <span class="keyword">for</span> (ExcelExportStrategy e : excelExportStrategies) &#123;</span><br><span class="line">        log.info(<span class="string">&quot;excelExportStrategies：&quot;</span> + e.getType());</span><br><span class="line">    &#125;</span><br><span class="line">    log.info(time + <span class="string">&quot;===========&quot;</span>);</span><br><span class="line">    log.info(<span class="string">&quot;newExcelResponse.getResult(&#123;&#125;&quot;</span>, JSON.toJSONString(newExcelResponse.getResult()));</span><br><span class="line"></span><br><span class="line">    log.info(<span class="string">&quot;待处理数量：&quot;</span> + newExcelResponse.getResult().size());</span><br><span class="line"></span><br><span class="line">    <span class="comment">//没有导出计划退出</span></span><br><span class="line">    <span class="keyword">if</span> (newExcelResponse.getResult().isEmpty()) &#123;</span><br><span class="line">        <span class="keyword">return</span>;</span><br><span class="line">    &#125;</span><br><span class="line">    List&lt;ExcelReportParam&gt; params_wai = <span class="keyword">new</span> ArrayList&lt;ExcelReportParam&gt;();</span><br><span class="line"></span><br><span class="line">    newExcelResponse.getResult().forEach(excel -&gt; &#123;</span><br><span class="line">        log.info(<span class="string">&quot;id:::::::::::&quot;</span> + excel.getId());</span><br><span class="line">        params_wai.add(</span><br><span class="line">                ExcelReportParam</span><br><span class="line">                        .builder()</span><br><span class="line">                        .id(excel.getId())</span><br><span class="line">                        .status(<span class="string">&quot;1&quot;</span>)</span><br><span class="line">                        .build());</span><br><span class="line">    &#125;);</span><br><span class="line"></span><br><span class="line">    ExcelReportUpdateBatchRequest request_wai = <span class="keyword">new</span> ExcelReportUpdateBatchRequest();</span><br><span class="line">    request_wai.setParams(params_wai);</span><br><span class="line">    <span class="comment">//修改导出计划状态为1</span></span><br><span class="line">    excelReportWriteFacade.updateBatch(request_wai);</span><br></pre></td></tr></table></figure>

<ul>
<li>开始执行导出修改任务状态为成功</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line">        <span class="comment">//修改导出计划状态为1</span></span><br><span class="line">        excelReportWriteFacade.updateBatch(request_wai);</span><br><span class="line"></span><br><span class="line">        List&lt;ExcelReportParam&gt; params_run = <span class="keyword">new</span> ArrayList&lt;ExcelReportParam&gt;();</span><br><span class="line">        newExcelResponse.getResult().forEach(excel -&gt; &#123;</span><br><span class="line">            <span class="keyword">try</span> &#123;</span><br><span class="line">                log.info(<span class="string">&quot;export start reportType:&quot;</span> + excel.getReportType() + <span class="string">&quot;,requestJson:&quot;</span> + excel.getRequestJson() + <span class="string">&quot;fileName:&quot;</span> + excel.getFileName());</span><br><span class="line">                <span class="comment">//开始执行需要导出的数据查询</span></span><br><span class="line">                String token = excelExportStrategyService.execute(excel.getReportType(), excel.getRequestJson(), excel.getFileName());</span><br><span class="line">                log.info(<span class="string">&quot;TOKEN:&quot;</span> + token);</span><br><span class="line">                <span class="keyword">if</span> (StringUtils.isBlank(token)) &#123;</span><br><span class="line">                    params_run.add(</span><br><span class="line">                            ExcelReportParam</span><br><span class="line">                                    .builder()</span><br><span class="line">                                    .id(excel.getId())</span><br><span class="line">                                    .status(<span class="string">&quot;4&quot;</span>)</span><br><span class="line">                                    .build());</span><br><span class="line">                &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                    params_run.add(</span><br><span class="line">                            ExcelReportParam</span><br><span class="line">                                    .builder()</span><br><span class="line">                                    .id(excel.getId())</span><br><span class="line">                                    .filePath(token)</span><br><span class="line">                                    .status(<span class="string">&quot;3&quot;</span>)</span><br><span class="line">                                    .build());</span><br><span class="line">                &#125;</span><br><span class="line"></span><br><span class="line">            &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">                log.error(e.getMessage(), e);</span><br><span class="line">                System.out.println(<span class="string">&quot;excel定时任务导出异常&gt;&gt;&gt;&gt;&gt;&quot;</span> + e);</span><br><span class="line">                String errorInfo = Throwables.getStackTraceAsString(e).length() &gt; <span class="number">1000</span></span><br><span class="line">                        ? Throwables.getStackTraceAsString(e).substring(<span class="number">0</span>, <span class="number">1000</span>)</span><br><span class="line">                        : Throwables.getStackTraceAsString(e);</span><br><span class="line">                params_run.add(</span><br><span class="line">                        ExcelReportParam</span><br><span class="line">                                .builder()</span><br><span class="line">                                .id(excel.getId())</span><br><span class="line">                                .status(<span class="string">&quot;4&quot;</span>)</span><br><span class="line">                                .build());</span><br><span class="line">                log.info(<span class="string">&quot;excel定时任务导出异常&gt;&gt;&gt;&gt;&gt;&quot;</span> + e);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;);</span><br><span class="line"></span><br><span class="line">        ExcelReportUpdateBatchRequest request_run = <span class="keyword">new</span> ExcelReportUpdateBatchRequest();</span><br><span class="line">        request_run.setParams(params_run);</span><br><span class="line">        excelReportWriteFacade.updateBatch(request_run);</span><br><span class="line"></span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>通过报表类型找到具体的导出任务实现类执行导出</p>
</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserExcelExportStrategyService</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 导出任务Map,每一个ExcelExportStrategy就是一个导出任务,通过报表类型区分</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    Map&lt;String, ExcelExportStrategy&gt; excelExportStrategyMap = Maps.newHashMap();</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 使用有参构造让IOC容器自动注入导出任务实现类</span></span><br><span class="line"><span class="comment">     * 并封装到导出任务Map中</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> excelExportStrategies</span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> <span class="title">UserExcelExportStrategyService</span><span class="params">(List&lt;ExcelExportStrategy&gt; excelExportStrategies)</span> </span>&#123;</span><br><span class="line">        <span class="keyword">for</span> (ExcelExportStrategy excelExportStrategy : excelExportStrategies) &#123;</span><br><span class="line">            excelExportStrategyMap.put(excelExportStrategy.getType(), excelExportStrategy);</span><br><span class="line">        &#125;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="comment">/**</span></span><br><span class="line"><span class="comment">     * 根据传入的报表任务从map中获取具体的导出任务实现类执行导出</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> type</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> requestJson</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@param</span> fileName</span></span><br><span class="line"><span class="comment">     * <span class="doctag">@return</span></span></span><br><span class="line"><span class="comment">     */</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">execute</span><span class="params">(String type, String requestJson, String fileName)</span> </span>&#123;</span><br><span class="line">        log.info(excelExportStrategyMap + <span class="string">&quot;&lt;&lt;&lt;&lt;excelExportStrategyMap:::type&gt;&gt;:::&quot;</span> + type);</span><br><span class="line">        log.info(<span class="string">&quot;requestJson&gt;&gt;&gt;::&quot;</span> + requestJson);</span><br><span class="line">        log.info(<span class="string">&quot;fileName&gt;&gt;&gt;::&quot;</span> + fileName);</span><br><span class="line">        <span class="keyword">return</span> excelExportStrategyMap.get(type).execute(requestJson, fileName);</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<ol start="6">
<li><p>根据导出报表类型、导出数据查询请求参数、导出文件名开始查询导出数据封装ExcelTemplate上传阿里云OSS返回下载路径</p>
<ul>
<li>注入需要查询导出数据相关的Facade</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Service</span></span><br><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserAuthenticationExcelExportOssStrategyImpl</span> <span class="keyword">implements</span> <span class="title">ExcelExportStrategy</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> UserAuthenticationReadFacade userAuthenticationReadFacade;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> UserRegionRelationsReadFacade userRegionRelationsReadFacade;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> UcUserReadFacade ucUserReadFacade;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> UserExcelExportHelper excelExportHelper;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> UserThirdPartyRegistry registry;</span><br></pre></td></tr></table></figure>

<ul>
<li>通过传入的请求参数调用Facade查询导出数据</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//使用JSON反序列请求参数</span></span><br><span class="line">UserRegionRelationsPagingRequest pagingRequest =</span><br><span class="line">        JSON.parseObject(requestJson, UserRegionRelationsPagingRequest.class);</span><br><span class="line"></span><br><span class="line">log.info(<span class="string">&quot;user.authentication.export, UserRegionRelationsPagingRequest = &#123;&#125;&quot;</span>, pagingRequest);</span><br><span class="line"><span class="comment">//需要导出的数据</span></span><br><span class="line">List&lt;UserAuthenticationExcelTemplate&gt; authenticationList = Lists.newArrayList();</span><br><span class="line"><span class="keyword">int</span> pageNo = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">int</span> pageSize = <span class="number">200</span>;</span><br><span class="line">Response&lt;List&lt;UserRegionRelationsInfo&gt;&gt; userRegionRelationsInfoResponse =</span><br><span class="line">        userRegionRelationsReadFacade.noPagingRegionRelations(pagingRequest);</span><br><span class="line"><span class="keyword">if</span> (userRegionRelationsInfoResponse.isSuccess() &amp;&amp; !CollectionUtils.isEmpty(userRegionRelationsInfoResponse.getResult())) &#123;</span><br><span class="line">    <span class="comment">//根据返回值取出 authId 集合</span></span><br><span class="line">    List&lt;Long&gt; authIdList = userRegionRelationsInfoResponse.getResult().stream().map(UserRegionRelationsInfo::getAuthId).collect(Collectors.toList());</span><br><span class="line">    <span class="keyword">while</span> (<span class="keyword">true</span>) &#123;</span><br><span class="line">        Response&lt;Paging&lt;UserAuthenticationInfo&gt;&gt; response = <span class="keyword">null</span>;</span><br><span class="line">        <span class="comment">//根据 authIdList 查询出</span></span><br><span class="line">        <span class="comment">// pagingUserAuthenticationByAuthIdList</span></span><br><span class="line">        UserAuthenticationPagingByAuthIdListRequest userAuthenticationPagingByAuthIdListRequest =</span><br><span class="line">                <span class="keyword">new</span> UserAuthenticationPagingByAuthIdListRequest();</span><br><span class="line">        userAuthenticationPagingByAuthIdListRequest.setPageNo(pageNo);</span><br><span class="line">        userAuthenticationPagingByAuthIdListRequest.setPageSize(pageSize);</span><br><span class="line">        userAuthenticationPagingByAuthIdListRequest.setAuthIdList(authIdList);</span><br><span class="line">        response = userAuthenticationReadFacade.pagingUserAuthenticationByAuthIdList(userAuthenticationPagingByAuthIdListRequest);</span><br><span class="line">        <span class="keyword">if</span> (CollectionUtils.isEmpty(response.getResult().getData())) &#123;</span><br><span class="line">            <span class="keyword">break</span>;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">if</span> (response.isSuccess()) &#123;</span><br><span class="line">            List&lt;UserAuthenticationInfo&gt; data = response.getResult().getData();</span><br><span class="line">            fillSalesmanName(data);</span><br><span class="line">            <span class="comment">// 先把userRegionRelations表数据的结果集 处理成 字典Map,key2与key1 值相同时，后值覆盖前值。</span></span><br><span class="line">            Map&lt;Long, UserRegionRelationsInfo&gt; maps = userRegionRelationsInfoResponse.getResult().stream().collect(Collectors.toMap(UserRegionRelationsInfo::getAuthId, Function.identity(), (key1, key2) -&gt; key2));</span><br><span class="line">            <span class="comment">//处理返回的结果集</span></span><br><span class="line">            <span class="keyword">for</span> (UserAuthenticationInfo item : data) &#123;</span><br><span class="line">                UserRegionRelationsInfo u = maps.get(item.getId());</span><br><span class="line">                <span class="comment">//赋值过程</span></span><br><span class="line">                item.setAuthenticationStatus(u.getAuthenticationStatus());</span><br><span class="line">                item.setAuthenticationDesc(u.getAuthenticationDesc());</span><br><span class="line">                item.setChannelId(u.getCustomerChannel());</span><br><span class="line">                item.setSellerId(u.getSellerId());</span><br><span class="line">                item.setSalesManId(u.getSalesmanId());</span><br><span class="line">                item.setSalesManTel(u.getSalesmanTel());</span><br><span class="line">                UserAuthenticationExcelTemplate userAuthenticationExcelTemplate = <span class="keyword">new</span> UserAuthenticationExcelTemplate();</span><br><span class="line">                BeanUtils.copyProperties(item, userAuthenticationExcelTemplate);</span><br><span class="line">                StringBuilder sb = <span class="keyword">new</span> StringBuilder();</span><br><span class="line">                sb.append(item.getProvince());</span><br><span class="line">                sb.append(item.getCity());</span><br><span class="line">                sb.append(item.getRegion());</span><br><span class="line">                sb.append(item.getAddress());</span><br><span class="line">                String address = sb.toString();</span><br><span class="line">                <span class="keyword">if</span> (address.indexOf(<span class="string">&quot;null&quot;</span>) != -<span class="number">1</span>) &#123;</span><br><span class="line">                    address = Strings.EMPTY;</span><br><span class="line">                &#125;</span><br><span class="line">                userAuthenticationExcelTemplate.setAddress(address);</span><br><span class="line">                userAuthenticationExcelTemplate.setShippingAddress(address);</span><br><span class="line">                authenticationList.add(userAuthenticationExcelTemplate);</span><br><span class="line">            &#125;</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            log.error(<span class="string">&quot;UserAuthenticationExcelExportOssStrategyImpl execute failed, param:&#123;&#125; &quot;</span>, userAuthenticationPagingByAuthIdListRequest);</span><br><span class="line"></span><br><span class="line">            <span class="keyword">throw</span> <span class="keyword">new</span> RestException(response.getError());</span><br><span class="line">        &#125;</span><br><span class="line">        pageNo++;</span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure>

<ul>
<li><p>通过XSSFWorkbook获取输出流</p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//获取输出流</span></span><br><span class="line">ByteArrayOutputStream outputStream = excelExportHelper.generateExcel(authenticationList, UserAuthenticationExcelTemplate.class);</span><br><span class="line"><span class="keyword">byte</span>[] content = outputStream.toByteArray();</span><br><span class="line">is = <span class="keyword">new</span> ByteArrayInputStream(content);</span><br></pre></td></tr></table></figure>

<p><strong>具体代码:</strong></p>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"> <span class="function"><span class="keyword">public</span> ByteArrayOutputStream <span class="title">generateExcel</span><span class="params">(List list, Class&lt;?&gt; clazz)</span> <span class="keyword">throws</span> IllegalAccessException </span>&#123;</span><br><span class="line"></span><br><span class="line">        XSSFWorkbook wb = <span class="keyword">new</span> XSSFWorkbook();</span><br><span class="line">        XSSFSheet xssfSheet = wb.createSheet(clazz.getSimpleName());</span><br><span class="line"></span><br><span class="line">        XSSFCellStyle titleStyle = (XSSFCellStyle) wb.createCellStyle();</span><br><span class="line">        titleStyle.setLocked(<span class="keyword">true</span>);</span><br><span class="line"></span><br><span class="line">        XSSFCellStyle cellStyle = (XSSFCellStyle) wb.createCellStyle();</span><br><span class="line">        cellStyle.setFillForegroundColor(IndexedColors.YELLOW.getIndex());</span><br><span class="line"></span><br><span class="line">        <span class="keyword">int</span> i = <span class="number">0</span>;</span><br><span class="line">        <span class="comment">//标题</span></span><br><span class="line">        Row titleRow = xssfSheet.createRow(i);</span><br><span class="line">        <span class="keyword">for</span> (Field field : clazz.getDeclaredFields()) &#123;</span><br><span class="line">            ExcelExportCell excelAnnotation = field.getAnnotation(ExcelExportCell.class);</span><br><span class="line">            <span class="keyword">if</span> (excelAnnotation != <span class="keyword">null</span>) &#123;</span><br><span class="line">                <span class="keyword">int</span> columnIndex = excelAnnotation.colIndex();</span><br><span class="line">                Cell cell = titleRow.createCell(columnIndex);</span><br><span class="line">                cell.setCellValue(excelAnnotation.titleName());</span><br><span class="line"><span class="comment">//                log.info(&quot;title:::::::::::&quot;+excelAnnotation.titleName());</span></span><br><span class="line"><span class="comment">//                if (excelAnnotation.isLock()) &#123;</span></span><br><span class="line"><span class="comment">//                    cell.setCellStyle(cellStyle);</span></span><br><span class="line"><span class="comment">//                &#125;</span></span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">for</span> (Object obj : list) &#123;</span><br><span class="line">            i++;</span><br><span class="line">            Row row = xssfSheet.createRow(i);</span><br><span class="line">            <span class="keyword">for</span> (Field field : clazz.getDeclaredFields()) &#123;</span><br><span class="line">                field.setAccessible(<span class="keyword">true</span>);</span><br><span class="line">                ExcelExportCell excelAnnotation = field.getAnnotation(ExcelExportCell.class);</span><br><span class="line">                <span class="keyword">if</span> (excelAnnotation != <span class="keyword">null</span>) &#123;</span><br><span class="line">                    <span class="keyword">int</span> columnIndex = excelAnnotation.colIndex();</span><br><span class="line">                    Cell cell = row.createCell(columnIndex);</span><br><span class="line"><span class="comment">//                    log.info(&quot;rownum:::::::::::&quot;+columnIndex);</span></span><br><span class="line"><span class="comment">//                    log.info(&quot;row:::::::::::&quot;+field.getName()+&quot;:&quot;+field.get(obj));</span></span><br><span class="line">                    <span class="keyword">if</span> (<span class="keyword">null</span> != field.get(obj)) &#123;</span><br><span class="line">                        cell.setCellValue(field.get(obj).toString());</span><br><span class="line">                    &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">                        cell.setCellValue(<span class="string">&quot;&quot;</span>);</span><br><span class="line">                    &#125;</span><br><span class="line">                &#125;</span><br><span class="line">            &#125;</span><br><span class="line">        &#125;</span><br><span class="line">        <span class="keyword">try</span> &#123;</span><br><span class="line">            ByteArrayOutputStream outputStream = <span class="keyword">new</span> ByteArrayOutputStream();</span><br><span class="line">            wb.write(outputStream);</span><br><span class="line">            outputStream.flush();</span><br><span class="line">            <span class="comment">// outputStream.close();</span></span><br><span class="line">            <span class="keyword">return</span> outputStream;</span><br><span class="line">        &#125; <span class="keyword">catch</span> (IOException e) &#123;</span><br><span class="line">            log.error(<span class="string">&quot;fail to download excel template:&#123;&#125;, cause:&#123;&#125;&quot;</span>,</span><br><span class="line">                    clazz.getSimpleName(), Throwables.getStackTraceAsString(e));</span><br><span class="line">            <span class="keyword">return</span> <span class="keyword">null</span>;</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125;</span><br></pre></td></tr></table></figure></li>
<li><p>导出数据上传阿里云OSS</p>
</li>
</ul>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//上传阿里云OSS获取下载路径</span></span><br><span class="line">filePath = registry.findBy(UserObjectStorageFactory.class).uploadFile(name + <span class="string">&quot;.xlsx&quot;</span>, is);</span><br></pre></td></tr></table></figure>

<pre><code>1. 通过OSSClient上传阿里云
</code></pre>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Data</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@ConfigurationProperties(prefix = &quot;useross.third-party.client.aliyun.oss&quot;)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">AcsOssClient</span> </span>&#123;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String endpoint;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String accessKeyId;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String accessKeySecret;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> String bucketName;</span><br><span class="line"></span><br><span class="line">    <span class="keyword">private</span> OSSClient ossClient;</span><br><span class="line"></span><br><span class="line">    <span class="function"><span class="keyword">public</span> OSSClient <span class="title">getInstance</span><span class="params">()</span></span>&#123;</span><br><span class="line">        <span class="keyword">if</span> (ossClient == <span class="keyword">null</span>) &#123;</span><br><span class="line">            ossClient = <span class="keyword">new</span> OSSClient(endpoint, accessKeyId, accessKeySecret);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="comment">//如果bucket不存在，就创建</span></span><br><span class="line">        <span class="keyword">if</span> (!ossClient.doesBucketExist(bucketName)) &#123;</span><br><span class="line">            ossClient.createBucket(bucketName);</span><br><span class="line">            CreateBucketRequest createBucketRequest = <span class="keyword">new</span> CreateBucketRequest(bucketName);</span><br><span class="line">            createBucketRequest.setCannedACL(CannedAccessControlList.Private);</span><br><span class="line">            ossClient.createBucket(createBucketRequest);</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> ossClient;</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure>

<p>通过配置文件设置需要的参数，通过@ConfigurationProperties注解注入属性，通过getInstance()方法初始化OSSClient对象并返回</p>
<ol start="2">
<li>注入AcsOssClient调用API执行上传</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">@Slf4j</span></span><br><span class="line"><span class="meta">@Component</span></span><br><span class="line"><span class="meta">@UserThirdPartyProvider(clazz = UserObjectStorageFactory.class, code = &quot;aliyun&quot;)</span></span><br><span class="line"><span class="meta">@ConditionalOnProperty(name = &quot;useross.third-party.storage.provider&quot;, havingValue = &quot;aliyun&quot;, matchIfMissing = true)</span></span><br><span class="line"><span class="keyword">public</span> <span class="class"><span class="keyword">class</span> <span class="title">UserAliyunOssFactory</span> <span class="keyword">implements</span> <span class="title">UserObjectStorageFactory</span> </span>&#123;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line">    <span class="meta">@Autowired</span></span><br><span class="line">    <span class="keyword">private</span> AcsOssClient ossClient;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">uploadFile</span><span class="params">(String objectName, InputStream is)</span> </span>&#123;</span><br><span class="line">        String bucketName = ossClient.getBucketName();</span><br><span class="line">        log.info(<span class="string">&quot;uploadFile ------------------&gt;&gt;&gt;&gt;&gt; &#123;&#125;,&#123;&#125;,&#123;&#125;&quot;</span>,bucketName,objectName,is);</span><br><span class="line">        ossClient.getInstance().putObject(bucketName, objectName, is);</span><br><span class="line">        log.info(<span class="string">&quot;endpoint::::::::::::::::::::::::::&quot;</span>+ossClient.getEndpoint());</span><br><span class="line">        log.info(<span class="string">&quot;accessKeyId::::::::::::::::::::::::::&quot;</span>+ossClient.getAccessKeyId());</span><br><span class="line">        log.info(<span class="string">&quot;accessKeySecret::::::::::::::::::::::::::&quot;</span>+ossClient.getAccessKeySecret());</span><br><span class="line">        log.info(<span class="string">&quot;bucketName::::::::::::::::::::::::::&quot;</span>+ossClient.getBucketName());</span><br><span class="line">        <span class="keyword">return</span> <span class="string">&quot;https://&quot;</span> + bucketName + <span class="string">&quot;.&quot;</span> + ossClient.getEndpoint() + <span class="string">&quot;/&quot;</span> + objectName;</span><br><span class="line">    &#125;</span><br><span class="line"></span><br><span class="line">    <span class="meta">@Override</span></span><br><span class="line">    <span class="function"><span class="keyword">public</span> String <span class="title">getAccessUrl</span><span class="params">(String objectName)</span> </span>&#123;</span><br><span class="line">        String bucketName = ossClient.getBucketName();</span><br><span class="line"></span><br><span class="line">        <span class="comment">// 默认一小时后过期</span></span><br><span class="line">        Calendar now = Calendar.getInstance();</span><br><span class="line">        now.add(Calendar.HOUR, <span class="number">1</span>);</span><br><span class="line"></span><br><span class="line">        <span class="keyword">return</span> ossClient.getInstance().generatePresignedUrl(bucketName, objectName, now.getTime()).toString();</span><br><span class="line">    &#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></li>
<li><p>拿到阿里云OSS下载路径修改misc导出任务状态可下载并设置下载路径</p>
</li>
</ol>
<figure class="highlight java"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br></pre></td><td class="code"><pre><span class="line">  log.info(<span class="string">&quot;export start reportType:&quot;</span> + excel.getReportType() + <span class="string">&quot;,requestJson:&quot;</span> + excel.getRequestJson() + <span class="string">&quot;fileName:&quot;</span> + excel.getFileName());</span><br><span class="line">        <span class="comment">//开始执行需要导出的数据查询</span></span><br><span class="line">        String token = excelExportStrategyService.execute(excel.getReportType(), excel.getRequestJson(), excel.getFileName());</span><br><span class="line">        log.info(<span class="string">&quot;TOKEN:&quot;</span> + token);</span><br><span class="line">        <span class="keyword">if</span> (StringUtils.isBlank(token)) &#123;</span><br><span class="line">            params_run.add(</span><br><span class="line">                    ExcelReportParam</span><br><span class="line">                            .builder()</span><br><span class="line">                            .id(excel.getId())</span><br><span class="line">                            .status(<span class="string">&quot;4&quot;</span>)</span><br><span class="line">                            .build());</span><br><span class="line">        &#125; <span class="keyword">else</span> &#123;</span><br><span class="line">            params_run.add(</span><br><span class="line">                    ExcelReportParam</span><br><span class="line">                            .builder()</span><br><span class="line">                            .id(excel.getId())</span><br><span class="line">                            .filePath(token)</span><br><span class="line">                            .status(<span class="string">&quot;3&quot;</span>)</span><br><span class="line">                            .build());</span><br><span class="line">        &#125;</span><br><span class="line"></span><br><span class="line">    &#125; <span class="keyword">catch</span> (Exception e) &#123;</span><br><span class="line">        log.error(e.getMessage(), e);</span><br><span class="line">        System.out.println(<span class="string">&quot;excel定时任务导出异常&gt;&gt;&gt;&gt;&gt;&quot;</span> + e);</span><br><span class="line">        String errorInfo = Throwables.getStackTraceAsString(e).length() &gt; <span class="number">1000</span></span><br><span class="line">                ? Throwables.getStackTraceAsString(e).substring(<span class="number">0</span>, <span class="number">1000</span>)</span><br><span class="line">                : Throwables.getStackTraceAsString(e);</span><br><span class="line">        params_run.add(</span><br><span class="line">                ExcelReportParam</span><br><span class="line">                        .builder()</span><br><span class="line">                        .id(excel.getId())</span><br><span class="line">                        .status(<span class="string">&quot;4&quot;</span>)</span><br><span class="line">                        .build());</span><br><span class="line">        log.info(<span class="string">&quot;excel定时任务导出异常&gt;&gt;&gt;&gt;&gt;&quot;</span> + e);</span><br><span class="line">    &#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">ExcelReportUpdateBatchRequest request_run = <span class="keyword">new</span> ExcelReportUpdateBatchRequest();</span><br><span class="line">request_run.setParams(params_run);</span><br><span class="line">excelReportWriteFacade.updateBatch(request_run);</span><br></pre></td></tr></table></figure>


    </div>
<div>
  
    <div>
    
        <div style="text-align:center;color: #ccc;font-size:14px;">-------------本文结束<i class="fa fa-paw"></i>感谢您的阅读-------------</div>
    
</div>

  
</div>

    
    
    
        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://wan-lei8.gitee.io/2021/11/17/%E5%BC%82%E6%AD%A5%E5%AF%BC%E5%87%BA/" title="异步导出">https://wan-lei8.gitee.io/2021/11/17/异步导出/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" rel="noopener" target="_blank"><i class="fab fa-fw fa-creative-commons"></i>BY-NC-SA</a> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2021/11/17/%E6%B3%A8%E8%A7%A3-ConditionalOnProperty%E4%BD%BF%E7%94%A8/" rel="prev" title="注解@ConditionalOnProperty使用">
      <i class="fa fa-chevron-left"></i> 注解@ConditionalOnProperty使用
    </a></div>
      <div class="post-nav-item">
    <a href="/2022/01/10/bug-record/" rel="next" title="bug_record">
      bug_record <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  



          </div>
          

<script>
  window.addEventListener('tabs:register', () => {
    let { activeClass } = CONFIG.comments;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%B0%81%E8%A3%85%E6%9F%A5%E8%AF%A2%E5%AF%BC%E5%87%BA%E6%95%B0%E6%8D%AE%E7%9A%84%E8%AF%B7%E6%B1%82%E5%8F%82%E6%95%B0%E8%BD%AC%E6%88%90JSON%E5%AD%97%E7%AC%A6%E4%B8%B2"><span class="nav-number">1.</span> <span class="nav-text">封装查询导出数据的请求参数转成JSON字符串</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E5%B0%81%E8%A3%85%E5%AF%BC%E5%87%BA%E4%BF%A1%E6%81%AF%E5%8C%85%E6%8B%AC%E6%96%87%E4%BB%B6%E7%B1%BB%E5%9E%8B%E3%80%81%E6%96%87%E4%BB%B6%E5%90%8D%E3%80%81%E6%8A%A5%E8%A1%A8%E7%B1%BB%E5%9E%8B%E3%80%81%E6%89%80%E5%B1%9E%E4%B8%AD%E5%8F%B0"><span class="nav-number">2.</span> <span class="nav-text">封装导出信息包括文件类型、文件名、报表类型、所属中台</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E8%BF%9C%E7%A8%8B%E8%B0%83%E7%94%A8misc%E7%BB%BC%E5%90%88%E6%9C%8D%E5%8A%A1%E4%BF%9D%E5%AD%98%E5%AF%BC%E5%87%BA%E4%BF%A1%E6%81%AF"><span class="nav-number">3.</span> <span class="nav-text">远程调用misc综合服务保存导出信息</span></a></li><li class="nav-item nav-level-5"><a class="nav-link" href="#%E4%BD%BF%E7%94%A8%E5%AE%9A%E6%97%B6%E4%BB%BB%E5%8A%A1%E6%AF%8F%E4%B8%89%E5%88%86%E9%92%9F%E8%AF%BB%E5%8F%96misc%E9%9C%80%E8%A6%81%E5%AF%BC%E5%87%BA%E4%BF%A1%E6%81%AF"><span class="nav-number">4.</span> <span class="nav-text">使用定时任务每三分钟读取misc需要导出信息</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt=""
      src="/images/avatar.png">
  <p class="site-author-name" itemprop="name"></p>
  <div class="site-description" itemprop="description"></div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives">
          <span class="site-state-item-count">41</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <a href="https://github.com/yourname" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;yourname" rel="noopener" target="_blank"><i class="fab fa-github fa-fw"></i>GitHub</a>
      </span>
      <span class="links-of-author-item">
        <a href="/malegod958@163.com" title="E-Mail → malegod958@163.com"><i class="fa fa-envelope fa-fw"></i>E-Mail</a>
      </span>
  </div>
  <div class="cc-license motion-element" itemprop="license">
    <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh" class="cc-opacity" rel="noopener" target="_blank"><img src="/images/cc-by-nc-sa.svg" alt="Creative Commons"></a>
  </div>



      </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

        

<div class="copyright">
  
  &copy; 2018 – 
  <span itemprop="copyrightYear">2022</span>
  <span class="with-love">
    <i class="heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">万磊</span>
</div>
  <div class="powered-by">

  </div>

        








      </div>
    </footer>
  </div>

  
  
  <script color='' opacity='0.5' zIndex='-1' count='99' src="/lib/canvas-nest/canvas-nest.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  















  

  

  
	<script type="text/javascript" src="//cdn.bootcss.com/canvas-nest.js/1.0.0/canvas-nest.min.js"></script>
	

<script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"log":false,"pluginJsPath":"lib/","pluginModelPath":"assets/","pluginRootPath":"live2dw/","tagMode":false});</script></body>
</html>
<!-- 页面点击小红心 -->
<script type="text/javascript" src="/js/src/clicklove.js"></script>
